<template>
  <div id="app">
    <h1 style="text-align: center; margin: 20px 0;">图书管理系统</h1>
    <div class="container">
      <add-book-form @add-book="handleAddBook" />
      <book-table 
        :books="books" 
        @delete-book="handleDeleteBook" 
      />
    </div>
  </div>
</template>

<script>
import BookTable from './components/BookTable.vue'
import AddBookForm from './components/AddBookForm.vue'

export default {
  name: 'App',
  components: {
    BookTable,
    AddBookForm
  },
  data() {
    return {
      books: [
        {"id": 1, "title": "Python编程", "author": "John Doe", "copies": 4},
        {"id": 2, "title": "历史的秘密", "author": "Jane Smith", "copies": 3},
        {"id": 3, "title": "宇宙探索", "author": "Emily Brown", "copies": 2},
        {"id": 4, "title": "健康生活", "author": "Mike Johnson", "copies": 5},
        {"id": 5, "title": "数学之美", "author": "Sarah Lee", "copies": 4},
        {"id": 6, "title": "艺术欣赏", "author": "David White", "copies": 3},
        {"id": 7, "title": "编程入门", "author": "Alice Green", "copies": 2},
        {"id": 8, "title": "科幻世界", "author": "Frank Black", "copies": 5},
        {"id": 9, "title": "自然奇观", "author": "Grace Blue", "copies": 4},
        {"id": 10, "title": "音乐之声", "author": "Tom Red", "copies": 3}
      ]
    }
  },
  methods: {
    handleAddBook(newBook) {
      // 生成新ID
      const newId = this.books.length > 0 ? Math.max(...this.books.map(book => book.id)) + 1 : 1
      this.books.push({
        id: newId,
        ...newBook
      })
      this.$message.success('图书添加成功！')
    },
    handleDeleteBook(bookId) {
      this.books = this.books.filter(book => book.id !== bookId)
      this.$message.success('图书删除成功！')
    }
  }
}
</script>

<style>
.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}
</style>